//
//  SCSysHelper.m
//  Shuaiche
//
//  Created by 党帅 on 2019/8/8.
//  Copyright © 2019 ShuaiChe. All rights reserved.
//

#import "SCSysHelper.h"

//#import <CoreTelephony/CTCall.h>
//#import <CoreTelephony/CTCallCenter.h>
// 拨打电话的回调方法
//CTCallCenter *callCenter;
//callCenter = [[CTCallCenter alloc] init];
//callCenter.callEventHandler = ^(CTCall* call) {
//    if ([call.callState isEqualToString:CTCallStateDisconnected])
//    {
//        NSLog(@"Call has been disconnected");
//    }
//    else if ([call.callState isEqualToString:CTCallStateConnected])
//    {
//        NSLog(@"Call has just been connected");
//    }
//    else if([call.callState isEqualToString:CTCallStateIncoming])
//    {
//        NSLog(@"Call is incoming");
//    }
//    else if ([call.callState isEqualToString:CTCallStateDialing])
//    {
//        NSLog(@"call is dialing");
//    }
//    else
//    {
//        NSLog(@"Nothing is done");
//    }
//};
@implementation SCSysHelper

+ (void)callPhone:(NSString *)phoneNumber completionHandler:(void (^ __nullable)(BOOL success))completion {
    if (phoneNumber.length == 0) {
        return;
    }
    NSString *urlString = [NSString stringWithFormat:@"telprompt://%@",phoneNumber];
    NSURL *url = [NSURL URLWithString:urlString];
    if([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]){
        [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:completion];
    }else{
        [[UIApplication sharedApplication] openURL:url];
    }
}

+ (BOOL)openWeChat {
    return [self openAppUrlPath:@"weixin://"];
}

+ (void)openAppStore {
    [self openAppUrlPath:@"https://itunes.apple.com/cn/app/%E5%B8%85%E8%BD%A6/id1324959608?l=zh&ls=1&mt=8"];
}

+ (BOOL)openAppUrlPath:(NSString *)urlPath {
    NSURL *url = [NSURL URLWithString:urlPath];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
        return YES;
    } else {
        return NO;
    }
}


+ (void)changeStatusBarStyle:(UIStatusBarStyle)style {
    if (style == UIStatusBarStyleLightContent) {
        [UIApplication sharedApplication].statusBarStyle = style;
    } else {
        if (@available(iOS 13.0, *)) {
            [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
        } else {
            [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
        }
    }
}

@end
